package com.kun.rental.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kun.rental.entity.RentalType;
import com.kun.rental.entity.Role;
import com.kun.rental.service.IRentalTypeService;
import com.kun.rental.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 *  出租类型
 * </p>
 *
 * @author ikun
 * @since 2024-07-04
 */
@RestController
@RequestMapping("/rental/rentalType")
public class RentalTypeController {

    @Autowired
    private IRentalTypeService rentalTypeService;


    /**
     * 分页查询
     * @param start
     * @param size
     * @param rentalType
     * @return
     */
    @PostMapping("/{start}/{size}")
    public Result search(@PathVariable int start, @PathVariable int size,
                         @RequestBody RentalType rentalType){
        Page<RentalType> page=new Page<>(start,size);
        return Result.success(rentalTypeService.searchByPage(page,rentalType));
    }


    /**
     * 新增
     * @param rentalType
     * @return
     */
    @PostMapping("/save")
    public Result save(@RequestBody RentalType rentalType) {
        return rentalTypeService.save(rentalType)?Result.success() : Result.fail();
    }


    /**
     * 更新
     * @param rentalType
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody RentalType rentalType){
        return rentalTypeService.updateById(rentalType)?Result.success():Result.fail();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    public Result delete(@PathVariable String ids){
        return rentalTypeService.delete(ids)?Result.success():Result.fail();
    }


    /**
     * 查询所有车辆类型
     * @return
     */
    @GetMapping("/selectAll")
    public Result seleceAll(){
        return Result.success(rentalTypeService.list());
    }


}
